﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for UFVBLL
/// </summary>
public class UFVBLL
{
	public UFVBLL()
	{
		//
		// TODO: Add constructor logic here
		//
	}

    public static UFV rowToDto(dsUFV.UFVDSRow UFVRow)
    {

        UFV objUFV = new UFV();
        objUFV.IUfv_id = UFVRow.iUfv_id;
        objUFV.DtFecha = UFVRow.dtFecha;
        objUFV.IValor = UFVRow.iValor;
        objUFV.ICreadoPor = UFVRow.iCreadoPor;


        return objUFV;
    }
    public static List<UFV> GetAll()
    {
        List<UFV> ListaDeUFV = new List<UFV>();
        try
        {



            dsUFVTableAdapters.UFVDSTableAdapter UFVAdapter
                = new dsUFVTableAdapters.UFVDSTableAdapter();
            dsUFV.UFVDSDataTable UFVDataTable = UFVAdapter.GetAll_UFV();

            foreach (dsUFV.UFVDSRow row in UFVDataTable)
            {
                UFV objUFV = rowToDto(row);
                ListaDeUFV.Add(objUFV);
            }
        }
        catch (Exception ex)
        {

            //Manejar Excepcion
        }
        return ListaDeUFV;
    }
    public static UFV GetByPK(int pk)
    {

        try
        {

            dsUFVTableAdapters.UFVDSTableAdapter UFVAdapter
                = new dsUFVTableAdapters.UFVDSTableAdapter();
            dsUFV.UFVDSDataTable UFVDataTable
                = UFVAdapter.GetByPk_UFV(pk);

            UFV objUFV = rowToDto(UFVDataTable[0]);
            return objUFV;
        }
        catch (Exception ex)
        {

            //Manejar Excepcion
        }
        return null;
    }

    public static int InsertarUFV(DateTime dtFecha, decimal iValor, int iCreadoPor)
    {

        try
        {

            dsUFVTableAdapters.UFVDSTableAdapter UFVAdapter
                = new dsUFVTableAdapters.UFVDSTableAdapter();


            int? nuevaPK = 0;

            UFVAdapter.Insertar_UFV(dtFecha, iValor, iCreadoPor, ref nuevaPK);

            return (int)nuevaPK;
        }
        catch (Exception ex)
        {

            //Manejar Excepcion
        }
        return 0;
    }

    public static bool ModificarUFV(int pk, DateTime dtFecha, decimal iValor, int iCreadoPor)
    {

        try
        {

            dsUFVTableAdapters.UFVDSTableAdapter UFVAdapter
                = new dsUFVTableAdapters.UFVDSTableAdapter();

            UFVAdapter.Modificar_UFV(pk, dtFecha,iValor, iCreadoPor);


            return true;
        }
        catch (Exception ex)
        {

            //Manejar Excepcion
        }
        return false;
    }

    public static bool EliminarUFV(int pk)
    {

        try
        {

            dsUFVTableAdapters.UFVDSTableAdapter UFVAdapter
                = new dsUFVTableAdapters.UFVDSTableAdapter();

            UFVAdapter.Eliminar_UFV(pk);


            return true;
        }
        catch (Exception ex)
        {

            //Manejar Excepcion
        }
        return false;
    }


    public static void InsertarUFV(int p)
    {
        throw new NotImplementedException();
    }
}